package searchalgo;


class BinarySearch{
	
	public static int doSearch(int[] array,int element){
		
		int start = 0;
		int end = array.length-1;
		while(start<end){
		int middle = (start+end)/2;
		System.out.println(middle);
		
			if(array[middle]== element){
				return middle;
			}else if(array[middle]>element){
				end = middle-1;
			}else if(array[middle]<element){
				start = middle+1;
			}
		}
		return -1;
	}
	
}
public class SearchAlgo {

	
	public static void main(String[] args) {
		int array[] = {0,1,2,3,4,5,6,7,8,9};
		System.out.println("Index is "+BinarySearch.doSearch(array, 4));
	}

}
